package com.tanhua.server.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVO;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Xiao
 * @date 2021/10/23
 */
@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;
    /**
     * 用户通用数据-读取
     * @return
     */
    @GetMapping("settings")
    public ResponseEntity settings() {
        SettingsVO settingsVO = settingsService.getSettingsVO();
        return ResponseEntity.ok(settingsVO);
    }

    /**
     * 设置陌生人问题-保存
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map<String, String> map) {
        String content = map.get("content");
        settingsService.questions(content);
        return ResponseEntity.ok("设置成功！");
    }

    /**
     * 通知设置-保存
     * @param map
     * @return
     */
    @PostMapping("notifications/setting")
    public ResponseEntity notificationsSetting(@RequestBody Map<String, Boolean> map) {
        Boolean likeNotification = map.get("likeNotification");
        Boolean pinglunNotification = map.get("pinglunNotification");
        Boolean gonggaoNotification = map.get("gonggaoNotification");
        settingsService.notificationsSetting(likeNotification, pinglunNotification, gonggaoNotification);
        return ResponseEntity.ok("设置成功！");
    }

    /**
     * 黑名单-翻页列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/blacklist")
    public ResponseEntity blackList(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pageResult = settingsService.blackList(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 黑名单-移除
     * @param blackUserId
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity removeBlacklist(@PathVariable("uid") Long blackUserId) {
        settingsService.removeBlacklist(blackUserId);
        return ResponseEntity.ok("操作成功！");
    }

    /**
     * 修改手机号-发送验证码
     * @return
     */
    @PostMapping("/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode() {
        settingsService.sendVerificationCode();
        return ResponseEntity.ok("验证码已发送");
    }

    /**
     * 修改手机号-校验验证码
     * @param map
     * @return
     */
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map<String, String> map) {
        String verificationCode = map.get("verificationCode");
        Boolean verification = settingsService.checkVerificationCode(verificationCode);
        Map<String, Boolean> map1 = new HashMap<>();
        map1.put("verification", verification);
        return ResponseEntity.ok(map1);
    }

    /**
     * 修改手机号-保存
     * @param map
     * @return
     */
    @PostMapping("/phone")
    public ResponseEntity phone(@RequestBody Map<String, String> map) {
        String phone = map.get("phone");
        settingsService.phone(phone);
        return ResponseEntity.ok("修改成功！");
    }
}
